package jdbc_firstlook;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

// 0、创建工程，导入驱动jar包
public class JDBC {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1、注册驱动
        //Class.forName("com.mysql.jdbc.Driver");

        //2、获取连接
        String url = "jdbc:mysql://127.0.0.1:3306/itcase";
        String userName = "root";
        String passWord = "202111a.";
        Connection conn = DriverManager.getConnection(url,userName,passWord);

        //3、定义SQL语句
        String sql = "update user set age = 19 where id = 1";

        //4、获取执行SQL对象
        Statement stmt = conn.createStatement();

        //5、执行SQL,并返回结果(影响行数)
        int count = stmt.executeUpdate(sql);

        //6、处理返回结果
        System.out.println(count);
        if(count > 0){
            System.out.println("修改成功！");
        }else {
            System.out.println("修改失败！");
        }

        //7、释放资源
        conn.close();
        stmt.close();
    }
}
